import json
from src.modules.memory.service import MemoryDetailService
from flask import Blueprint, request, Response, make_response

api = Blueprint("memory_detail", __name__)

@api.route("/memory/details", methods = ['GET'])
def load_memory_details():
    args = request.args
    list = MemoryDetailService.load_memory_details(args)
    return Response(json.dumps({ "code": 200, "data": list }), status = 200, mimetype = "application/json")

@api.route("/memory/download", methods = ['POST'])
def download_memory_details():
    args = request.form
    output = MemoryDetailService.download_memory_detail(args)
    response = make_response(output)
    response.headers['Content-Disposition'] = 'attachment; filename=memory_detail.txt'
    response.headers['Content-type'] = 'text/plain'
    return response
